package net.googlecode.harchenko.task5;

import net.googlecode.harchenko.task5.calculator.Calculator;
import net.googlecode.harchenko.task5.calculator.SalaryCalculatorFactory;
import net.googlecode.harchenko.task5.model.Boss;
import net.googlecode.harchenko.task5.model.Employee;
import net.googlecode.harchenko.task5.model.Manager;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;

/**
 * Main application printing report and using collections.
 */
public class SalaryApp {


    public static void main(String[] args) {

        Task5 task5 = new Task5();
        ArrayList<Manager> lst = new ArrayList<Manager>();
        Collections.addAll(lst, createBoss(), createManager(), createEmployee(), createEmployeeTwo(),
                            createManagerTwo(), createManagerThree());

        for (Manager prs : lst) {
            calculateSalary(prs);
        }

        if (args.length > 0) {
            if (args[0].equals("code")) {
                task5.codeSort(lst);
            } else {
                if (args[0].equals("name")) {
                    task5.nameSort(lst);
                } else {
                    if (args[0].equals("salary")) {
                        task5.salarySort(lst);
                    } else {
                        System.out.println("Wrong parameter.");

                    }
                }
            }


        }
        ;
    }

    private static BigDecimal calculateSalary(Manager person) {
        Calculator salaryCalculator = SalaryCalculatorFactory.getCalculator(person);
        person.setSalary(salaryCalculator.calculateSalary(person));
        return salaryCalculator.calculateSalary(person);
    }

    public static Manager createManager() {
        Manager manager = new Manager();
        manager.setFirstName("Ivan");
        manager.setLastName("Ivanov");
        manager.setAge(30);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(new BigDecimal(25));
        return manager;
    }

    public static Boss createBoss() {
        Boss boss = new Boss();
        boss.setFirstName("Petr");
        boss.setLastName("Petrov");
        boss.setAge(35);
        boss.setBonusAmount(new BigDecimal(1000));
        boss.setRate(new BigDecimal(50));

        return boss;
    }

    public static Employee createEmployee() {
        Employee employee = new Employee();
        employee.setFirstName("Semen");
        employee.setLastName("Semenov");
        employee.setAge(55);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1500));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(8));

        return employee;
    }

    public static Employee createEmployeeTwo() {
        Employee employee = new Employee();
        employee.setFirstName("Afanasiy");
        employee.setLastName("Afanasievich");
        employee.setAge(39);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(2000));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(9));

        return employee;
    }

    public static Manager createManagerTwo() {
        Manager manager = new Manager();
        manager.setFirstName("Ivan");
        manager.setLastName("Ivanovich");
        manager.setAge(30);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(new BigDecimal(25));

        return manager;
    }

    public static Manager createManagerThree() {
        Manager manager = new Manager();
        manager.setFirstName("Andrey");
        manager.setLastName("Andrienko");
        manager.setAge(45);
        manager.setPerHour(true);
        manager.setBonus(true);
        manager.setBonusAmount(new BigDecimal(1000));
        manager.setRate(new BigDecimal(30));

        return manager;
    }
}
